package com.shiyi.shiyiaicodefather.core.saver;

import cn.hutool.core.util.StrUtil;
import com.shiyi.shiyiaicodefather.ai.model.HtmlCodeResult;
import com.shiyi.shiyiaicodefather.exception.BusinessException;
import com.shiyi.shiyiaicodefather.exception.ErrorCode;
import com.shiyi.shiyiaicodefather.model.enums.CodeGenTypeEnum;

import static com.shiyi.shiyiaicodefather.core.CodeFileSaver.writeToFile;

/**
 * HTML代码文件保存器
 *
 */
public class HtmlCodeFileSaverTemplate extends CodeFileSaverTemplate<HtmlCodeResult> {
  @Override
  protected CodeGenTypeEnum getCodeType() {
    return CodeGenTypeEnum.HTML;
  }

  @Override
  protected void saveFiles(HtmlCodeResult result, String baseDirPath) {
    writeToFile(baseDirPath, "index.html", result.getHtmlCode());
  }


  @Override
  protected void validateInput(HtmlCodeResult result) {
    super.validateInput(result);
    // HTML 代码不能为空
    if (StrUtil.isBlank(result.getHtmlCode())) {
      throw new BusinessException(ErrorCode.SYSTEM_ERROR, "HTML代码内容不能为空");
    }
  }
}
